package com.atguigu04.example.exer5_objarr1;

/**
 * ClassName: StudentUtil
 * Package: com.atguigu04.example.exer5_objarr1
 * Description:
 *
 * @Author BuTang
 * @Create 2023/2/27 22:23
 * @Version 1.0
 */
public class StudentUtil {
    /**
     * 打印指定年级的学生
     * @param arr
     * @param target
     */
    public void printStudentsWithIndex(Student[] arr, int target){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].grade == target) {
                System.out.print("年级是"+ arr[i].grade+"学号是" +arr[i].number+"成绩是"+arr[i].socre);
            }
        }
    }

    /**
     * 遍历所有学生
     * @param arr
     */
    public void printStudents(Student[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print("年级是"+ arr[i].grade+"学号是" +arr[i].number+"成绩是"+arr[i].socre);
        }
    }

    public void sortStudents(Student[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            boolean flag =true;
            for (int j = 0; j < arr.length -1; j++) {
                if (arr[j].socre >= arr[j+1].socre) {
                    Student  temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1]=temp;
                    flag =false;
                }
            }
            if (flag == true) {
                break;
            }
            }
        }
    }


